import Buff from '@/Buff';
import BuffUtil from '@/BuffUtil';
import RandomUtil from '@/RandomUtil';
import UnitCommon from 'code/Core/Common/UnitCommon';
import AbilityBase from 'code/Scripts/Abilities/base/AbilityBase';
/**
 * 撕裂攻击
 **/
export default class MSK_Silie extends AbilityBase {
    static instance: MSK_Silie;
    buffType: AppBuffType = {
        id: 'buff_MSK_Silie',
        art: this.art,
        name: this.abilityName,
        ubertip: this.ubertip,
        stackCountMax: -1,
        dur: 12,
        onInterval: this.buffInterval.bind(this),
        interval: 2,
        isDebuff: true,
    };
    buffInterval(buff: Buff) {
        if (!buff.getCaster()) return;
        let at = UnitCommon.取攻击(buff.getCaster()) * 0.2 * buff.stackCount;
        DamageSystemInstance.applyPhysicalDamage(buff.getParent(), buff.getCaster(), at);
    }
    constructor(id: string = 'Myh2') {
        super(id);
        MSK_Silie.instance = this;
        this.init();
        EventManager.onTakeAttack(this.onSpellEffect.bind(this));
    }
    init() {
        BuffUtil.registerBuffType(this.buffType);
    }
    cast<T extends Object = any>(tarX: number, tarY: number, source: unit, target: unit, data?: T): void {
        BuffUtil.addBuff(target, this.buffType.id, source);
    }
    onSpellEffect(d: DamageEventData) {
        if (GetUnitAbilityLevel(d.source, this.id) == 0) return;
        let r = RandomUtil.randomPercent();
        if (r > 0.15) return;
        this.cast(0, 0, d.source, d.target, d);
    }
}
